package com.atguigu.msmservice.controller;

import com.atguigu.common.R;
import com.atguigu.msmservice.service.MsmService;
import com.atguigu.msmservice.utils.RandomUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author panghl
 * @Date 2021/2/2 22:11
 * @Description 短信服务
 **/
@RestController
@Api(tags = {"短信服务"})
@RequestMapping("/edumsm/msm")
public class MsmController {

    @Autowired
    private MsmService msmService;

    //发送短信的方法
    @GetMapping("/send/{phone}")
    public R sendSms(@PathVariable("phone") String phone) {
        //生成随机值，传递阿里云进行发送
        String code = RandomUtil.getFourBitRandom();
        Map<String, Object> param = new HashMap<>();
        param.put("code", code);
        boolean isSend = msmService.send(param,phone);
        if (isSend) {
            return R.ok();
        } else {
            return R.error();
        }
    }

}
